package ${table.packageNames.service_impl};

<#list table.importPackages.serviceImpl as pkg>
import ${pkg};
</#list>

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
public class ${table.serviceImplName}<#if isMybatisPlus> extends ServiceImpl<${table.mapperName}, ${table.entityName}></#if> implements ${table.serviceName} {

    <#assign mapperName = "${table.capitalEntityName}Mapper">
<#if isMybatisPlus>
    <#assign mapperName = "this.baseMapper">
<#else >
    <#if isGenerateBaseCRUD>
    @Resource
    private ${table.mapperName} ${table.capitalMapperName};
</#if>
</#if>

<#if isGenerateBaseCRUD>
    @Override
    public boolean saveBatch(List<${table.entityName}> list){
        return isSuccess(${mapperName}.saveBatch(list));
    }

    @Override
    public boolean save(${table.entityName} ${table.capitalEntityName}){
        return isSuccess(${mapperName}.save(${table.capitalEntityName}));
    }

    @Override
    public boolean saveNotEmpty(${table.entityName} ${table.capitalEntityName}){
        return isSuccess(${mapperName}.saveNotEmpty(${table.capitalEntityName}));
    }

    @Override
    public boolean deleteById(Serializable id){
        return isSuccess(${mapperName}.deleteById(id));
    }

    @Override
    public boolean updateById(${table.entityName} ${table.capitalEntityName}){
        return isSuccess(${mapperName}.updateById(${table.capitalEntityName}));
    }

    @Override
    public boolean updateNotEmptyById(${table.entityName} ${table.capitalEntityName}){
        return isSuccess(${mapperName}.updateNotEmptyById(${table.capitalEntityName}));
    }

    @Override
    public List<${table.entityName}> findListByEntity(${table.entityName} ${table.capitalEntityName}){
        return ${mapperName}.findListByEntity(${table.capitalEntityName});
    }

    @Override
    public ${table.entityName} get${table.entityName}ByEntity(${table.entityName} ${table.capitalEntityName}){
        return ${mapperName}.get${table.entityName}ByEntity(${table.capitalEntityName});
    }

    @Override
    public ${table.entityName} get${table.entityName}ById(Serializable id){
        return ${mapperName}.get${table.entityName}ById(id);
    }

<#if isPageMethod>
    @Override
    public PageInfo<${table.entityName}> queryTableData(${table.entityName} ${table.capitalEntityName}, Integer pageIndex, Integer pageSize){
        PageHelper.startPage(pageIndex, pageSize);
        List<${table.entityName}> list = ${mapperName}.findListByEntity(${table.capitalEntityName});
        PageInfo<${table.entityName}> info = new PageInfo<>(list);
        return info;
    }
</#if>


    /**
     * 是否成功 如果传入的num大于0则是true
     * @param num 数值
     * @return 是否成功
     */
    private boolean isSuccess(int num){
        return num > 0;
    }

</#if>
}
